package com.photographysharing.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.photographysharing.common.ThreadLocalOperation;
import com.photographysharing.dto.FansDTO;
import com.photographysharing.entity.Fans;
import com.photographysharing.entity.Follows;
import com.photographysharing.response.DatasResponse;
import com.photographysharing.service.FansService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("fans")
public class FansController {
    private FansService fansService;

    public FansController(FansService fansService) {
        this.fansService = fansService;
    }

    @GetMapping("/fans")
    public DatasResponse<FansDTO> fans(String userId){
        return fansService.getAll(userId);
    }

    @GetMapping("/isFans")
    public boolean isFans(String fansId){
        String userId = ThreadLocalOperation.getThreadLocalUserId();
        Fans follows = fansService.getOne(new QueryWrapper<Fans>().eq("user_id",userId).eq("fans_id",fansId));
        return follows==null?false:true;
    }
}
